package com.dao;

import com.utils.DatabaseOperations;
import com.utils.DatabaseOperationsImp;
import com.utils.JdbcUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class MatchResultEndDao extends DatabaseOperations implements DatabaseOperationsImp {
    String table="match_result_end";
    String[] nations={"id","team_id","goal_difference","goal","yellow_card","red_card","grade"};
    public boolean addData(String[] columnName, String[] str) {
        return super.addData(table, columnName, str);
    }


    public boolean deleteData(String columnName, String newData) {
        return super.deleteData(table, columnName, newData);
    }


    public boolean updateData(String columnName, String newData, String index, String idValue) {
        return super.updateData(table, columnName, newData, index, idValue);
    }


    public String[][] queryData(String index, String idValue) {
        return super.queryData(table, index, idValue);
    }


   /* public String[][] browsingData() {
        return super.
                browsingData(table);
    }*/

    public String[][] browsingData(){
        try {
            Connection con = JdbcUtils.getConnection();
            String sql="select * from `"+table+"` order by grade desc,goal_difference desc,goal desc,red_card asc,yellow_card asc" ;
            //配置结果集，使查询后的结果集的指针可以自由移动
            PreparedStatement pst = con.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
            ResultSet resultSet = pst.executeQuery();
            //将结果集转换成二维字符串数组，并返回
            return JdbcUtils.changeString(resultSet);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }

    public String[] getNations() {
        return this.nations;
    }

    public String[] nationsV(String item) {
        return super.nationsV("match_result_end", item);
    }
}
